import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

public class Bullet2 extends GameObject{// 보완중

//	public Image image;
//	public int x, y;
	public int a;
	public float vx, vy;// 벡터속도
	public float vx0, vy0;// 세타만큼 회전시킨 벡터속도
	public float distance;
	public float theta;
	public int thetaControl;
	public float rad;
	public float c;
	public float s;
	Rectangle rect;
//	public boolean active;// 활성화 여부 -> 이 값이 false이면 관리 목록에서 제거
	private int enemy3x;
	private int enemy3y;

	public Bullet2(Image image, int x, int y) {
		enemy3x = MainScreen.enemy3x;
		enemy3y = MainScreen.enemy3y;

		this.image = image;
		this.x = x;
		this.y = y;

		abstand();
		VectorX();
		VectorY();

		rad();
		cos();
		sin();

		tVectorX();
		tVectorY();

		rect = new Rectangle(image.getWidth(null), image.getHeight(null));
	}

	public void update() {
		x += vx0;
		y += vy0;
		if(x<(0-image.getWidth(null)) || y>(Constants.SCREEN_HEIGHT-image.getHeight(null)) || y<(0+image.getHeight(null))){
			active = false;
		}
		thetaControl++;
	}

	public void render(Graphics g) {
		if (active) {// 활성 상태일 경우에만 화면에 출력
			g.drawImage(image, x, y, null);
		}
	}

	public Rectangle getArea() {
		rect.x = x;
		rect.y = y;
		return rect;
	}

	public void rad() {
//		a=(int)(Math.random()*5);
//		switch(a){
//		case 0 : 
//			theta=300;
//			break;
//		case 1 :
//			theta=330;
//			break;
//		case 2 :
//			theta=1;
//			break;
//		case 3 :
//			theta=30;
//			break;
//		case 4 :
//			theta=60;
//			break;
//		}

		rad = (float) (Math.PI) / 180 * theta;	
	}

	public void cos() {
		c = (float) Math.cos(rad);
	}

	public void sin() {
		s = (float) Math.sin(rad);
	}

	public void tVectorX() {
		vx0 = (vx * c) - (vy * s);
	}

	public void tVectorY() {
		vy0 = (vx * s) - (vy * c);
	}

	public void abstand() {
		this.distance = (float) Math.sqrt(// 피타고라스
				(0 - enemy3x) * (0 - enemy3x)
						+ (enemy3y - Constants.SCREEN_HEIGHT / 2)
						* (enemy3y - Constants.SCREEN_HEIGHT / 2));
	}

	public void VectorX() {
		this.vx = (float) (((0 - enemy3x) / distance) * 20);
	}

	public void VectorY() {
		this.vy = (float) (((Constants.SCREEN_HEIGHT / 2 - enemy3y) / distance) * 20);
	}
}
